//
//  HomeController.swift
//  SkyApp
//
//  Created by 白翊 on 2021/12/20.
//

import UIKit
import FDFullscreenPopGesture
import SnapKit

class HomeController: BaseViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()

        fd_prefersNavigationBarHidden = true
        
        let size = WIDTH * 0.5
        let picture = UIImageView(image: "mumalogo", contentMode: .scaleAspectFit, frame: CGRect(x: (WIDTH - size) * 0.5, y: NAVBAR_HEIGHT, width: size, height: size))
        view.addSubview(picture)
        
        let animation = CAKeyframeAnimation(keyPath: "transform.rotation.z")
        animation.values = [0, -Double.pi * 0.05, 0, Double.pi * 0.05, 0]
        animation.isRemovedOnCompletion = false
        animation.duration = 2
        animation.repeatCount = MAXFLOAT
        picture.layer.add(animation, forKey: "animation")
        
        let items: [DifficultType] = [
            .easy,
            .middle,
            .difficult,
        ]
        let intervalH: CGFloat = 60
        let intervalV: CGFloat = 24
        let btn_height: CGFloat = 50
        let top = picture.bottom + (HEIGHT - NAVBAR_HEIGHT - TABBAR_HEIGHT - picture.bottom - intervalV * CGFloat(items.count) - btn_height * CGFloat(items.count)) * 0.5
        for (index, item) in items.enumerated() {
            let button = UIButton(title: item.desc, titleColor: .bg, fontSize: 16, frame: CGRect(x: intervalH, y: top + (intervalV + btn_height) * CGFloat(index), width: WIDTH - intervalH * 2, height: btn_height)) { [weak self] _ in
                
                let detailCtr = DetailController()
                detailCtr.difficultType = item
                self?.navigationController?.pushViewController(detailCtr, animated: true)
            }
            button.backgroundColor = .title
            button.setCornerRadius(radius: btn_height * 0.5)
            view.addSubview(button)
        }
    }

}
